package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.MesEquipment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:24:56
 */
@Repository
public class MesEquipmentDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(MesEquipmentDao.class);

    public MesEquipment insert(final MesEquipment mesEquipment) {
        insert("MesEquipment.insert", mesEquipment);
        return mesEquipment;
    }

    public Boolean updateInfoById(final MesEquipment mesEquipment) {
        return update("MesEquipment.updateInfoById", mesEquipment) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("MesEquipment.updateInfoByQuery", query) > 0;
    }

    public MesEquipment selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("MesEquipment.selectById", query);
    }

    public List<MesEquipment> selectByQuery(final Query query) {
        return queryForList("MesEquipment.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("MesEquipment.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        MesEquipment mesEquipment = new MesEquipment();
        mesEquipment.setDeleteFlag(1);
        mesEquipment.setId(id);
        mesEquipment.setEntId(entId);

        return update("MesEquipment.updateInfoById", mesEquipment) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("MesEquipment.deleteById", query) > 0;
    }
}